<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\index\controller\game;

/**
 * 微派H5支付
 *
 * @author SoChishun
 */
class Wiipayh5Controller extends \app\index\controller\BaseController {

    public function indexAction() {
        if ($this->loginInfo['currency'] < 1) {
            $this->error('您的竞猜币不足，请充值!', url('finance.recharge/recharge'));
        }
        return view();
    }

    public function dowiipayh5Action() {
        if ($this->loginInfo['currency'] < 1) {
            return ['success' => false, 'message' => '您的竞猜币不足，请充值!'];
        }
        $request = \think\Request::instance();
        $request->only(['da', 'xiao', 'dan', 'shuang']);
        $data = $request->param();
        $game = new \app\index\model\GameRecordModel();
        $result = $game->saveRecord($data, $this->loginInfo['id']);
        if (!$result['success']) {
            return ['success' => false, 'message' => $result['message']];
        }

        $out_trade_no = $result['message']['out_trade_no'];
        $amount = 0.01;

        $callback_url = url('game.game/result', 'out_trade_no=' . $out_trade_no); //支付成功后跳转的商户页面(用户看到的页面)
        $params = \app\index\model\finance\Wiipayh5Model::getPayConf($amount, $out_trade_no, $callback_url);
        return ['success' => true, 'message' => $params];
    }

}
